﻿using System;
using System.Collections.Generic;
using System.Text;
using Quartz;
using System.Data;
using Model.TransfersConfig;
using Model.Task;
using IBLL;
using Model.WebService;
using AppToolKit.Core.Context.Spring;
using IBLL.Business;



namespace BLL.Action.Core.Base
{
    public abstract class JobBase:IJob
    {
        private const string ID = "ID";
        private const string Action_Filed = "action";
        private const string Hotelid = "hotelid";
        private const string Interface = "interface";
        private const string DataSource = "datasource";
        private const string TableName = "center_table";
        private const string PrimaryKey = "primarykey";
        public const string ContextAware_Filed = "ContextAware";

        public ContextAware ContextAwareHolder { get; set; }
        public IActionFactory Factory { get; set; }

        public abstract ITaskBusiness TaskBusinessHolder { get; }

        //protected IAction Action;

        #region IJob Members

        public virtual void Execute(JobExecutionContext context)
        {
            Init(context);
           

        }

        #endregion

        public virtual void Init(JobExecutionContext context)
        {
            ContextAwareHolder = context.JobDetail.JobDataMap.Get(ContextAware_Filed) as ContextAware;

            Factory = new ActionFactory();
            ContextAwareHolder.AutowireObject(Factory);
             
        }
        protected virtual void GetTaskdefine(DataSet ds, List<TaskDefine> tasks)
        {

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                TaskDefine task = new TaskDefine();
                task.Action = Convert.ToString(dr[Action_Filed]);
                task.DataSource = Convert.ToString(dr[DataSource]);
                task.CenterTableName = Convert.ToString(dr[TableName]);
                task.Interface = Convert.ToString(dr[Interface]);
                task.Hotelid = Convert.ToString(dr[Hotelid]);
                task.PrimaryKey = Convert.ToString(dr[PrimaryKey]).Split(',');
                task.IsUpdate = true;
                tasks.Add(task);
            }
        }
        //protected virtual void GetAction(string action)
        //{
        //    Action=Factory.CreateAction(action);
              
        //}
        //protected virtual void AfterGetTask()
        //{
 
        //}

    }
}
